package entity

import "errors"

var (
	ErrInfoUserLogin     = errors.New("登录错误")
	ErrInfoUserNotFound  = errors.New("未找到账户")
	ErrInfoPassword      = errors.New("密码错误")
	ErrInfoUserExp       = errors.New("帐号过期")
	ErrInfoUserAreaLimit = errors.New("地区限制")
	ErrInfoUserVoidCombo = errors.New("套餐错误")
	ErrInfoUserBanned    = errors.New("帐号禁用")
	ErrInfoCacheEmpty    = errors.New("缓存为空")
)

const (
	ErrCodeSuccess   = 0
	ErrCodeUserLogin = -iota - 400
	ErrCodeUserNotFound
	ErrCodePassword
	ErrCodeUserExp
	ErrCodeAreaLimit
	ErrCodeUserVoidCombo
	ErrCodeUserBanned
	ErrCodeCacheEmpty
)

func UserCodeErr(tx int) error {
	switch tx {
	case ErrCodeUserLogin:
		return ErrInfoUserLogin
	case ErrCodeUserNotFound:
		return ErrInfoUserNotFound
	case ErrCodePassword:
		return ErrInfoPassword
	case ErrCodeUserExp:
		return ErrInfoUserExp
	case ErrCodeAreaLimit:
		return ErrInfoUserAreaLimit
	case ErrCodeUserVoidCombo:
		return ErrInfoUserVoidCombo
	case ErrCodeUserBanned:
		return ErrInfoUserBanned
	case ErrCodeCacheEmpty:
		return ErrInfoCacheEmpty
	default:
		return nil
	}
}

func UserErrCode(tx error) int {
	switch tx {
	case ErrInfoUserLogin:
		return ErrCodeUserLogin
	case ErrInfoUserNotFound:
		return ErrCodeUserNotFound
	case ErrInfoPassword:
		return ErrCodePassword
	case ErrInfoUserExp:
		return ErrCodeUserExp
	case ErrInfoUserAreaLimit:
		return ErrCodeAreaLimit
	case ErrInfoUserVoidCombo:
		return ErrCodeUserVoidCombo
	case ErrInfoUserBanned:
		return ErrCodeUserBanned
	case ErrInfoCacheEmpty:
		return ErrCodeCacheEmpty
	default:
		return ErrCodeSuccess
	}
}
